package com.ming_za.odupdaterserver.core.mco_core.Cmd.BasisCmd;

import com.ming_za.odupdaterserver.core.mco_core.API.CmdOperate;
import com.ming_za.odupdaterserver.core.mco_core.Cmd.CmdCreate;
import com.ming_za.odupdaterserver.core.utils.Msg;

import java.util.function.Consumer;

@CmdCreate(cmd = "confirm",hide = true)
public class ConfirmCmd implements CmdOperate {

    private final Msg msg;

    private Consumer<Void> preRunFunc = null;

    public ConfirmCmd(Msg msg) {
        this.msg = msg;
    }

    @Override
    public boolean onCommand(String command, String[] args) {

        if (preRunFunc != null) {
            preRunFunc.accept(null);
            preRunFunc = null;
        }else {
            msg.soutMsg("&c当前没有需要确认的指令");
        }

        return true;
    }

    public void addConfirm(Consumer<Void> func) {
        msg.soutMsg("&b请输入 confirm 确认继续运行");
        preRunFunc = func;
    }
}
